package com.netease.xone.itemview;

import protocol.meta.AppInfo;
import protocol.meta.AppInfoDetail;
import protocol.meta.AppPk;
import protocol.meta.AppPkItem;
import Utils.StackTraceUtil;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.netease.log.NTLog;
import com.netease.xone.R;


public class RenderInfoPK implements IRenderInfoBase, OnClickListener{

    private static final String TAG = RenderInfoPK.class.getSimpleName();

    private View mRoot;
    
    private TextView mBlueTitle;
    private TextView mBlueContent;
    private TextView mBlueNum;
    private ImageView mBlueWin;
    
    private TextView mRedTitle;
    private TextView mRedContent;
    private TextView mRedNum;
    private ImageView mRedWin;
    
    public RenderInfoPK(View v) {
        mRoot = v;
        
        mBlueTitle = (TextView)v.findViewById(R.id.blue_title);
        mBlueContent = (TextView)v.findViewById(R.id.blue_content);
        mBlueNum = (TextView)v.findViewById(R.id.blue_count);
        mBlueWin = (ImageView)v.findViewById(R.id.blue_win);
        v.findViewById(R.id.pk_support_blue).setOnClickListener(this);
        
        mRedTitle = (TextView)v.findViewById(R.id.red_title);
        mRedContent = (TextView)v.findViewById(R.id.red_content);
        mRedNum = (TextView)v.findViewById(R.id.red_count);
        mRedWin = (ImageView)v.findViewById(R.id.red_win);
        v.findViewById(R.id.pk_support_red).setOnClickListener(this);
    }

    @Override
    public void renderView(Context context, AppInfo appInfo) {
        renderView(context, appInfo.getPk());
    }

    @Override
    public void renderView(Context context, AppInfoDetail appInfoDetail) {
        
    }
    
    public void renderView(Context context, AppPk appPk) {
    	NTLog.d(TAG, StackTraceUtil.getMethodName());
    	
    	if (null == appPk) {
    		return;
    	}
    	
    	if (null == appPk.getItemList()) {
    		return;
    	}
    	
    	if (appPk.getItemList().size() < 2) {
    		return;
    	}
    	
    	if (appPk.getFinished()) {
    	    mRoot.findViewById(R.id.pk_support_blue).setSelected(true);
    	    mRoot.findViewById(R.id.pk_support_red).setSelected(true);
    	    mRoot.findViewById(R.id.pk_support_blue).setClickable(false);
    	    mRoot.findViewById(R.id.pk_support_red).setClickable(false);
    	    if (appPk.getItemList().get(0).getCount() > appPk.getItemList().get(1).getCount()) {
    	        mBlueWin.setVisibility(View.VISIBLE);
    	    } else {
    	        mRedWin.setVisibility(View.VISIBLE);
    	    }
    	} else {
    	    if (null != mBlueWin) {
    	        mBlueWin.setVisibility(View.GONE);
    	    }
    	    
    	    if (null != mRedWin) {
    	        mRedWin.setVisibility(View.GONE);
    	    }
    	}
    	
    	AppPkItem item = null;
    	item = appPk.getItemList().get(0);
    	mBlueTitle.setText(item.getTitle());
    	mBlueContent.setText(item.getDesc());
    	mBlueNum.setText(String.valueOf(item.getCount()));
    	
    	item = appPk.getItemList().get(1);
    	mRedTitle.setText(item.getTitle());
    	mRedContent.setText(item.getDesc());
    	mRedNum.setText(String.valueOf(item.getCount()));
    }
    
    @Override
    public void onClick(View v) {
        NTLog.d(TAG, StackTraceUtil.getMethodName());
    }
}
